//
//  SHPStatusRetweetView.swift
//  weibo
//
//  Created by songhuipan on 16/4/21.
//  Copyright © 2016年 songhuipan. All rights reserved.
//

import UIKit
import SnapKit
class SHPStatusRetweetView: UIView {
    
    var retweetViewBottomConstraint:Constraint?
    
    var status:SHPStatus? {
        didSet{
            // MARK:卸载约束
            retweetViewBottomConstraint?.uninstall()
            
            contentLabel.text = status?.retweeted_status?.text
            
            if status?.retweeted_status?.pic_urls != nil && status?.retweeted_status?.pic_urls?.count != 0  {
                
                pictureCollectionView.pic_urls = status!.retweeted_status!.pic_urls
                
                // MARK:转发微博底部约束设置
                self.snp_makeConstraints { (make) -> Void in
                    self.retweetViewBottomConstraint = make.bottom.equalTo(pictureCollectionView).offset(10).constraint
                }
                pictureCollectionView.hidden = false

            }else {
                  self.snp_makeConstraints(closure: { (make) -> Void in
                    self.retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
                pictureCollectionView.hidden = true
            }
            
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK:懒加载转发微博文字内容控件
    private lazy var contentLabel:UILabel = {
        let contentLabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 14)
        contentLabel.numberOfLines = 0
        return contentLabel
    }()
    // MARK:懒加载转发微博图片内容控件
    private lazy var pictureCollectionView :SHPPictureView = SHPPictureView()
}
extension SHPStatusRetweetView {
    
    private func setupUI (){
        
        backgroundColor = getColorWithRGB(237, green: 237, blue: 237)
        addSubview(contentLabel)
        addSubview(pictureCollectionView)
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(10)
            make.leading.equalTo(self).offset(10)
            make.trailing.equalTo(self).offset(-10)
        }
        pictureCollectionView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
//            make.leading.trailing.equalTo(contentLabel)
            make.leading.equalTo(contentLabel)
        }
        self.snp_makeConstraints { (make) -> Void in
           self.retweetViewBottomConstraint = make.bottom.equalTo(pictureCollectionView.snp_bottom).offset(10).constraint
        }
        
        
    }
}











